
$(function() {

});

var Exam = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},			
			
			"添加": function() {				
				if (!confirm("确认是否添加？")) {
					return false;
				}				
	
				var form = $("#form_add")[0];
				
				var body = { };
				body.category = form.category.value;
				body.name = form.name.value;
				body.content = form.content.value;
					
				$(this).dialog("close");
				
				// alert($.toJSON(body));	
				
				$.post('exam.php?do=Exam.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
		
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'exam.php?do=Exam.edit&id=' + id;
		var c2 = 'exam.php?do=Exam.view&id=' + id;
		
		var c6 = 'exam.php?do=Exam.question&id=' + id;
		var c7 = 'exam.php?do=Exam.emp&id=' + id;
		
		var a1 = ['编辑信息', 'url', 'Exam.dialog_edit_', '550x350'];	
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '700x550'];
		
		var a6 = ['试卷题目', 'url', 'Exam.dialog_question', '650x500'];
		var a7 = ['试卷发放', 'url', 'Exam.dialog_emp', '650x500'];
		
		var s = c1 + ", " + c2 + ", " + c6 + ", " + c7;

		return popup(e, [a1, a2, a6, a7], s);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
				
				var body = { };
				body.id = form.id.value;
				body.category = form.category.value;
				body.name = form.name.value;
				body.content = form.content.value;
				
				$(this).dialog("close");
	
				var url = 'exam.php?do=Exam.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_question: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var foo = [];
				$('#question option').each(function(i, n) {
					foo[i] = $(n).val();
				});
				
				var form = $("#form_edit")[0];
				
				var body = { };
				body.id = form.id.value;
				body.exam = form.exam.value;
				body.list = foo.join(",");
				
				$(this).dialog("close");
	
				var url = 'exam.php?do=Exam.questionPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_emp: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var foo = [];
				$('#emp option').each(function(i, n) {
					foo[i] = $(n).val();
				});
				
				var form = $("#form_edit")[0];
				
				var body = { };
				body.id = form.id.value;
				body.exam = form.exam.value;
				body.list = foo.join(",");
				
				$(this).dialog("close");
	
				var url = 'exam.php?do=Exam.empPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	}
};
